package com.zbkj.front.controller.user;

import com.alipay.api.domain.UserName;
import com.zbkj.common.annotation.LogControllerAnnotation;
import com.zbkj.common.enums.MethodType;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.*;
import com.zbkj.common.response.*;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.service.AttractActivityRecordService;
import com.zbkj.service.service.AttractActivityService;
import com.zbkj.service.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.ir.annotations.Ignore;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 邀约活动 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/front/attract/activity")
@Api(tags = "邀约活动") //配合swagger使用
public class AttractActivityController {

    @Autowired
    private AttractActivityService attractActivityService;

    @Autowired
    private AttractActivityRecordService attractActivityRecordService;

    @Autowired
    private UserService userService;

    @Ignore
    @ApiOperation(value = "最新邀约活动")
    @RequestMapping(value = "/latest", method = RequestMethod.GET)
    public CommonResult<AttractActivityLatestFrontResponse> getLatestActivity() {
        return CommonResult.success(attractActivityService.getLatestActivity());
    }

    @ApiOperation(value = "邀约活动列表") //配合swagger使用
    @RequestMapping(value = "/page/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<AttractActivityFrontPageDataResponse>> getList(@Validated AttractActivityFrontSearchRequest request,
                                                                             @ModelAttribute PageParamRequest pageParamRequest) {
        CommonPage<AttractActivityFrontPageDataResponse> attractActivityCommonPage = CommonPage.restPage(attractActivityService.getListH5(request, pageParamRequest));
        return CommonResult.success(attractActivityCommonPage);
    }

    @ApiOperation(value = "活动详情")
    @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
    public CommonResult<AttractActivityFrontDetailResponse> getActivityDetails(@PathVariable("id") Integer id) {
        return CommonResult.success(attractActivityService.getDetailsH5(id));
    }

    /**
     * 新增邀约活动记录表
     * @param attractActivityRecordFrontSaveRequest 新增参数
     * @author Caiyc
     * @since 2025-08-07
     */
    @ApiOperation(value = "新增记录")
    @RequestMapping(value = "/record/save", method = RequestMethod.POST)
    public CommonResult<Integer> save(@RequestBody @Validated AttractActivityRecordFrontSaveRequest attractActivityRecordFrontSaveRequest) {
        return CommonResult.success(attractActivityRecordService.createH5(attractActivityRecordFrontSaveRequest));
    }

    /**
     * 批量删除
     * @param request
     * @return
     * @author Caiyc
     * @since 2025-08-07
     */
    @LogControllerAnnotation(intoDB = true, methodType = MethodType.DELETE, description = "批量删除溯源套餐")
    @ApiOperation(value = "批量删除记录")
    @RequestMapping(value = "/record/batch/delete", method = RequestMethod.POST)
    public CommonResult<String> batchDelete(@RequestBody @Validated CommonBatchRequest request) {
        if (attractActivityRecordService.batchDelete(request.getIdList())) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    /**
     * 查询邀约活动记录表详情
     * @param id Integer
     * @author Caiyc
     * @since 2025-08-07
     */
    @ApiOperation(value = "记录详情")
    @RequestMapping(value = "/record/info/{id}", method = RequestMethod.GET)
    public CommonResult<AttractActivityRecordFrontDetailResponse> getDetails(@PathVariable("id") Integer id) {
        return CommonResult.success(attractActivityRecordService.getDetailsH5(id));
    }

    @ApiOperation(value = "我的记录列表") //配合swagger使用
    @RequestMapping(value = "/my/record/page/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<AttractActivityRecordFrontPageDataResponse>> getMyList(@ModelAttribute PageParamRequest pageParamRequest) {
        CommonPage<AttractActivityRecordFrontPageDataResponse> attractActivityRecordCommonPage =
                CommonPage.restPage(attractActivityRecordService.getMyListH5(pageParamRequest));
        return CommonResult.success(attractActivityRecordCommonPage);
    }

    @ApiOperation(value = "分享人信息")
    @RequestMapping(value = "/spread/info/{id}", method = RequestMethod.GET)
    public CommonResult<UserInfoResponse> getSpreadInfo(@PathVariable("id") Integer id) {
        return CommonResult.success(userService.getSpreadInfo(id));
    }

}



